package com.huawei.appgallery.appcomment.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextPaint;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.TextView;
import com.huawei.appgallery.appcomment.impl.bean.GetCommentResBean.AppCommentInfo;
import com.huawei.appgallery.appcomment.impl.bean.GetReplyResBean.ReplyComment;
import com.huawei.appgallery.appcomment.ui.AppReportActivity;
import com.huawei.appgallery.appcomment.ui.view.ApproveImageView;
import com.huawei.appgallery.appcomment.ui.view.CommentReplyItemView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import huawei.widget.HwTextView;
import java.io.Serializable;
import o.azb;
import o.bcg.e;
import o.bcg.h;
import o.bcg.i;
import o.bcp;
import o.bdb;
import o.bdj;
import o.bdl;
import o.bdv;
import o.beg;
import o.bei;
import o.ber;
import o.cdh;
import o.cea;
import o.cfw;
import o.cgy;
import o.cij;
import o.cks;
import o.ckt;
import o.cku;
import o.cvt;
import o.dof;
import o.epv;
import o.evx;

public class AppReplyListAdapter extends BaseAdapter implements o.bds.c, cij, OnMenuItemClickListener {
    public static final int REPLY_TYPE_DEVELOPER = 2;
    public static final int REPLY_TYPE_HUAWEI_CUSTOMER_SERVICE = 1;
    public static final int REPLY_TYPE_NORMAL = 0;
    private ReplyComment commentReplyInfo;
    private Context context = null;
    private c holder;
    private OnClickListener itemViewClickListener = null;
    private final byte[] lock = new byte[0];
    private PopupMenu popMenu = null;
    private bdl provider = null;

    static class b implements OnClickListener {
        private String ॱ;

        public b(String str) {
            this.ॱ = str;
        }

        public void onClick(View view) {
            ber.ॱ(this.ॱ, view.getContext());
        }
    }

    static class c {
        private TextView ʻ;
        private HwTextView ʼ;
        private TextView ʽ;
        private TextView ˊ;
        private ImageView ˊॱ;
        private TextView ˋ;
        private View ˋॱ;
        private ImageView ˎ;
        private TextView ˏ;
        private LinearLayout ͺ;
        private TextView ॱ;
        private LinearLayout ॱॱ;
        private ApproveImageView ᐝ;

        private c() {
            this.ˎ = null;
            this.ˏ = null;
            this.ॱ = null;
            this.ˊ = null;
            this.ˋ = null;
            this.ʻ = null;
            this.ʽ = null;
            this.ॱॱ = null;
            this.ᐝ = null;
            this.ʼ = null;
            this.ˊॱ = null;
        }
    }

    public AppReplyListAdapter(Context context, bdl o_bdl) {
        this.context = context;
        this.provider = o_bdl;
        this.provider.ˏ((o.bds.c) this);
    }

    public boolean hasMore() {
        if (this.provider != null) {
            return this.provider.ˊ();
        }
        return false;
    }

    public int getCount() {
        return this.provider.ॱ();
    }

    public Object getItem(int i) {
        return this.provider.ˊ(i);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(final int i, View view, ViewGroup viewGroup) {
        this.holder = null;
        if (view == null) {
            view = new CommentReplyItemView(this.context);
            this.holder = new c();
            azb.ˏ(view);
            this.holder.ˎ = (ImageView) view.findViewById(e.ॱㆍ);
            this.holder.ˏ = (TextView) view.findViewById(e.ॱﹳ);
            this.holder.ॱ = (TextView) view.findViewById(e.ॱᐧ);
            this.holder.ˋ = (TextView) view.findViewById(e.ॱᐨ);
            this.holder.ʻ = (TextView) view.findViewById(e.ॱـ);
            this.holder.ʽ = (TextView) view.findViewById(e.ˋʻ);
            this.holder.ˊ = (TextView) view.findViewById(e.ᐝʼ);
            this.holder.ॱॱ = (LinearLayout) view.findViewById(e.ᐝʻ);
            this.holder.ᐝ = (ApproveImageView) view.findViewById(e.ॱꞌ);
            this.holder.ʼ = (HwTextView) view.findViewById(e.ॱꜞ);
            this.holder.ˊॱ = (ImageView) view.findViewById(e.ʻʼ);
            this.holder.ͺ = (LinearLayout) view.findViewById(e.ʻʻ);
            this.holder.ˋॱ = view.findViewById(e.ˊᐝ);
            ber.ˋ(this.holder.ʽ);
            ber.ˋ(this.holder.ˋॱ);
            view.setTag(this.holder);
        } else {
            this.holder = (c) view.getTag();
        }
        this.commentReplyInfo = this.provider.ˊ(i);
        if (this.commentReplyInfo == null) {
            view = new View(this.context);
            view.setVisibility(8);
            return view;
        }
        this.holder.ͺ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ AppReplyListAdapter ˊ;

            public void onClick(View view) {
                this.ˊ.showCollectCommentPopup(view, i);
            }
        });
        this.commentReplyInfo.ˎ(i);
        setReplyItemData(this.holder, this.commentReplyInfo);
        this.holder.ॱॱ.setOnClickListener(new evx(this) {
            final /* synthetic */ AppReplyListAdapter ˏ;

            public void ˋ(View view) {
                this.ˏ.doRelpyApprove(i);
            }
        });
        view.setId(i);
        view.setOnClickListener(new ckt(this.itemViewClickListener));
        return view;
    }

    private void showCollectCommentPopup(View view, int i) {
        if (view != null) {
            this.popMenu = new PopupMenu(view.getContext(), view);
            Menu menu = this.popMenu.getMenu();
            this.popMenu.getMenuInflater().inflate(i.ˏ, menu);
            this.commentReplyInfo = this.provider.ˊ(i);
            MenuItem findItem = menu.findItem(e.ʽˋ);
            MenuItem findItem2 = menu.findItem(e.ʽʼ);
            if (this.commentReplyInfo.ˊ().equals(UserSession.getInstance().getUserId())) {
                findItem.setVisible(true);
                findItem2.setVisible(false);
            } else {
                findItem.setVisible(false);
                findItem2.setVisible(true);
            }
            this.popMenu.setOnMenuItemClickListener(this);
            this.popMenu.show();
        }
    }

    private void doRelpyApprove(int i) {
        int i2 = 0;
        ReplyComment ˊ = this.provider.ˊ(i);
        synchronized (this.lock) {
            if (ˊ.ˊॱ() == 1) {
                ˊ.ˏ(0);
                i2 = 1;
            } else {
                ˊ.ˏ(1);
            }
        }
        cfw.ˎ(new bcp(ˊ.ॱ(), cdh.ˎ((Activity) this.context), i2), new bdj(ˊ, this.context, i2));
    }

    private void setReplyItemData(c cVar, ReplyComment replyComment) {
        int i;
        String ˏ = replyComment.ˏ();
        if (TextUtils.isEmpty(ˏ)) {
            cVar.ˎ.setImageResource(o.bcg.c.ᐝॱ);
            cVar.ˎ.setTag("");
        } else if (!ˏ.equals((String) cVar.ˎ.getTag())) {
            cVar.ˎ.setTag(ˏ);
            cea.ˏ(cVar.ˎ, ˏ, "head_default_icon");
        }
        cVar.ˎ.setOnClickListener(new ckt(new b(replyComment.ˊ())));
        View ˏ2 = cVar.ˋॱ;
        if (replyComment.ʽ() == 6) {
            i = 0;
        } else {
            i = 8;
        }
        ˏ2.setVisibility(i);
        setText(cVar.ˋ, replyComment.ˋ());
        setText(cVar.ʻ, bei.ॱ(this.context, replyComment.ʻ()));
        setText(cVar.ʽ, replyComment.ʼ());
        cVar.ʽ.setTextIsSelectable(false);
        cVar.ʽ.setClickable(false);
        String str = "";
        if (1 == replyComment.ॱॱ()) {
            str = this.context.getResources().getString(h.ﾟ);
        } else if (2 == replyComment.ॱॱ()) {
            str = this.context.getResources().getString(h.ᐝˋ);
        } else {
            str = "";
        }
        cVar.ˏ.setText(replyComment.ˎ());
        cVar.ˊ.setText(replyComment.ͺ());
        cVar.ˊॱ.setVisibility(0);
        if (TextUtils.isEmpty(replyComment.ͺ())) {
            cVar.ˊॱ.setVisibility(8);
        }
        setText(cVar.ॱ, str);
        if (replyComment.ˊॱ() == 1) {
            cVar.ᐝ.setApproved(true);
        } else {
            cVar.ᐝ.setApproved(false);
        }
        CharSequence string = this.context.getString(h.ㆍ);
        if (replyComment.ॱˊ() != 0) {
            cVar.ʼ.setText(cgy.ˎ((double) replyComment.ॱˊ()));
        } else {
            cVar.ʼ.setText(string);
        }
        setImageContentDescription(cVar.ᐝ, replyComment.ॱˊ(), string);
        setReplyUserNameMaxWidth(cVar, replyComment, str);
    }

    private void setReplyUserNameMaxWidth(c cVar, ReplyComment replyComment, String str) {
        int i = 0;
        int contentWidth = getContentWidth(cVar.ˏ, replyComment.ˎ());
        int contentWidth2 = getContentWidth(cVar.ˊ, replyComment.ͺ());
        int contentWidth3 = getContentWidth(cVar.ॱ, str) + epv.ˋ(this.context, 18);
        int ˋ = epv.ˋ(this.context, 20);
        if (dof.ॱ(str)) {
            contentWidth3 = 0;
        }
        if (!dof.ॱ(replyComment.ͺ())) {
            i = ˋ;
        }
        int ॱ = (((azb.ॱ(this.context) - azb.ˊ(this.context)) - azb.ˏ(this.context)) - this.context.getResources().getDimensionPixelSize(o.bcg.b.ʽ)) - this.context.getResources().getDimensionPixelSize(o.bcg.b.ʻ);
        if (((contentWidth + contentWidth2) + contentWidth3) + i > ॱ) {
            cVar.ˏ.setMaxWidth(((ॱ - (contentWidth2 < epv.ˋ(this.context, 42) ? contentWidth2 : epv.ˋ(this.context, 42))) - contentWidth3) - i);
        }
    }

    private int getContentWidth(TextView textView, String str) {
        TextPaint paint = textView.getPaint();
        if (dof.ॱ(str)) {
            str = "";
        }
        return (int) paint.measureText(str);
    }

    private void setImageContentDescription(ImageView imageView, int i, String str) {
        if (i != 0) {
            imageView.setContentDescription(str);
        } else {
            imageView.setContentDescription(null);
        }
    }

    public void setItemViewClickListener(OnClickListener onClickListener) {
        this.itemViewClickListener = onClickListener;
    }

    private void setText(TextView textView, String str) {
        if (TextUtils.isEmpty(str)) {
            textView.setVisibility(8);
            return;
        }
        textView.setVisibility(0);
        textView.setText(str);
    }

    public void onDataUpdated() {
        notifyDataSetChanged();
    }

    private void showDeleteConfirmDialog() {
        CharSequence string = this.context.getResources().getString(h.ᐧ);
        cku ˋ = cku.ˋ(null, this.context.getResources().getString(h.ͺˏ));
        ˋ.ˎ(this.context);
        ˋ.ॱ(-1, string);
        ˋ.ॱ(new cks(this) {
            final /* synthetic */ AppReplyListAdapter ˏ;

            {
                this.ˏ = r1;
            }

            public void enableNetworking() {
                this.ˏ.doDeleteComment();
            }

            public void upgrade() {
            }

            public void ˋ() {
            }
        });
    }

    private void doDeleteComment() {
        if (this.commentReplyInfo != null && this.context != null) {
            cvt o_bdb = new bdb(this.commentReplyInfo.ॱ());
            o_bdb.setServiceType_(cdh.ˎ((Activity) this.context));
            cfw.ˎ(o_bdb, new bdv(this.commentReplyInfo.ॱ(), (Activity) this.context));
        }
    }

    public boolean onMenuItemClick(MenuItem menuItem) {
        if (menuItem.getItemId() == e.ʽˋ) {
            showDeleteConfirmDialog();
        } else if (!(menuItem.getItemId() != e.ʽʼ || this.commentReplyInfo == null || this.provider == null)) {
            AppCommentInfo ˏ = this.provider.ˏ();
            Serializable o_beg = new beg();
            o_beg.ˎ(this.commentReplyInfo.ˎ());
            o_beg.ˋ(this.commentReplyInfo.ʼ());
            o_beg.ˋ(11);
            o_beg.ॱ(this.commentReplyInfo.ˏ());
            o_beg.ˏ(ˏ.ʼ());
            o_beg.ˊ(this.commentReplyInfo.ॱ());
            Intent intent = new Intent(this.context, AppReportActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("reportContentInfo", o_beg);
            intent.putExtras(bundle);
            this.context.startActivity(intent);
        }
        return false;
    }
}
